home *** CD-ROM | disk | FTP | other *** search
/ Mac OS on the PowerPC Mic…rocessor - In Store Demo / Mac OS on the PowerPC Microprocessor.iso / MacOS / MacOS.dxr / 00100_parent-slider2-.ls < prev    next >
Encoding:
Text File  |  1996-05-13  |  4.3 KB  |  148 lines

  1. property minLoc, maxLoc, itemNo, currentNo, spriteNo, slideLocList1, slideLocList2, vertical, irev
  2.  
  3. on birth me, slideRect, spriteNumber
  4.   if getAt(slideRect, 1) = getAt(slideRect, 3) then
  5.     set vertical to 1
  6.     if getAt(slideRect, 2) < getAt(slideRect, 4) then
  7.       set minLoc to getAt(slideRect, 2)
  8.       set maxLoc to getAt(slideRect, 4)
  9.       set irev to 0
  10.     else
  11.       set minLoc to getAt(slideRect, 4)
  12.       set maxLoc to getAt(slideRect, 2)
  13.       set irev to 1
  14.     end if
  15.     set the locH of sprite spriteNo to getAt(slideRect, 1)
  16.   else
  17.     if getAt(slideRect, 2) = getAt(slideRect, 4) then
  18.       set vertical to 0
  19.       if getAt(slideRect, 1) < getAt(slideRect, 3) then
  20.         set minLoc to getAt(slideRect, 1)
  21.         set maxLoc to getAt(slideRect, 3)
  22.         set irev to 0
  23.       else
  24.         set minLoc to getAt(slideRect, 3)
  25.         set maxLoc to getAt(slideRect, 1)
  26.         set irev to 1
  27.       end if
  28.       set the locH of sprite spriteNo to getAt(slideRect, 2)
  29.     else
  30.       exit
  31.     end if
  32.   end if
  33.   set itemNo to EMPTY
  34.   set spriteNo to spriteNumber
  35.   set currentNo to EMPTY
  36.   set slideLocList1 to []
  37.   set slideLocList2 to []
  38.   return me
  39. end
  40.  
  41. on slideListSet me, ItemNumber
  42.   if ItemNumber = 1 then
  43.     set itemNo to 1
  44.   else
  45.     set slideStep to float(maxLoc - minLoc) / (ItemNumber - 1)
  46.     set slideHalfStep to integer(slideStep / 2)
  47.     set slideLocList1 to []
  48.     set slideLocList2 to []
  49.     repeat with n = 1 to ItemNumber - 1
  50.       add(slideLocList1, integer(minLoc + (slideStep * (n - 1))))
  51.       add(slideLocList2, integer(minLoc + (slideStep * (n - 1))) + slideHalfStep)
  52.     end repeat
  53.     add(slideLocList1, maxLoc)
  54.     sort(slideLocList2)
  55.     set itemNo to ItemNumber
  56.   end if
  57. end
  58.  
  59. on slideMouseDown me, mouseDownOperation, mouseUpOperation
  60.   if vertical then
  61.     set theOffset to the locV of sprite spriteNo - getAt(clickLoc(), 2)
  62.     repeat while the stillDown
  63.       set mouseloc to mouseV() + theOffset
  64.       if mouseloc < minLoc then
  65.         set mouseloc to minLoc
  66.       else
  67.         if mouseloc > maxLoc then
  68.           set mouseloc to maxLoc
  69.         end if
  70.       end if
  71.       set the locV of sprite spriteNo to mouseloc
  72.       updateStage()
  73.       add(slideLocList2, mouseloc)
  74.       set currentloc to getPos(slideLocList2, mouseloc)
  75.       deleteAt(slideLocList2, currentloc)
  76.       if irev then
  77.         set currentNo to itemNo - currentloc + 1
  78.       else
  79.         set currentNo to currentloc
  80.       end if
  81.       do(mouseDownOperation)
  82.     end repeat
  83.     if not voidp(currentloc) then
  84.       set the locV of sprite spriteNo to getAt(slideLocList1, currentloc)
  85.       updateStage()
  86.       if irev then
  87.         set currentNo to itemNo - currentloc + 1
  88.       else
  89.         set currentNo to currentloc
  90.       end if
  91.       do(mouseUpOperation)
  92.     end if
  93.   else
  94.     set theOffset to the locH of sprite spriteNo - getAt(clickLoc(), 1)
  95.     repeat while the stillDown
  96.       set mouseloc to mouseH() + theOffset
  97.       if mouseloc < minLoc then
  98.         set mouseloc to minLoc
  99.       else
  100.         if mouseloc > maxLoc then
  101.           set mouseloc to maxLoc
  102.         end if
  103.       end if
  104.       set the locH of sprite spriteNo to mouseloc
  105.       updateStage()
  106.       add(slideLocList2, mouseloc)
  107.       set currentloc to getPos(slideLocList2, mouseloc)
  108.       deleteAt(slideLocList2, currentloc)
  109.       if irev then
  110.         set currentNo to itemNo - currentloc + 1
  111.       else
  112.         set currentNo to currentloc
  113.       end if
  114.       do(mouseDownOperation)
  115.     end repeat
  116.     if not voidp(currentloc) then
  117.       set the locH of sprite spriteNo to getAt(slideLocList1, currentloc)
  118.       updateStage()
  119.       if irev then
  120.         set currentNo to itemNo - currentloc + 1
  121.       else
  122.         set currentNo to currentloc
  123.       end if
  124.       do(mouseUpOperation)
  125.     end if
  126.   end if
  127. end
  128.  
  129. on slideLocSet me, newNo
  130.   if (newNo >= 1) and (newNo <= itemNo) then
  131.     if vertical then
  132.       if irev then
  133.         set the locV of sprite spriteNo to getAt(slideLocList1, itemNo - newNo + 1)
  134.       else
  135.         set the locV of sprite spriteNo to getAt(slideLocList1, newNo)
  136.       end if
  137.     else
  138.       if irev then
  139.         set the locH of sprite spriteNo to getAt(slideLocList1, itemNo - newNo + 1)
  140.       else
  141.         set the locH of sprite spriteNo to getAt(slideLocList1, newNo)
  142.       end if
  143.     end if
  144.     updateStage()
  145.     set currentNo to newNo
  146.   end if
  147. end
  148.